<?php

class Emms_Form_Default_Login extends Zend_Form
{
    public function __construct() 
    {
        parent::__construct();
                
        $this->setName('Login');
        
        $this->setAttrib('title', $this->translate("Login form"));
        $this->setDescription($this->translate("Please complete the login form to continue"));
       
        $locale = new Zend_Form_Element_Hidden('locale');
        $locale->setValue(Zend_Registry::get('Zend_Locale'));
        
        $cl = new Zend_Form_Element_Hidden('cl');
        $cl->setValue(Zend_Registry::get('cl'));
        
        $db = new Zend_Form_Element_Select('db');
        $db->setLabel("Database")                
            ->setAttrib('size','4')
            ->setRequired(true)
            ->addMultiOptions(self::getDbOpt())
            ->removeDecorator('errors');              
        
        $username = new Zend_Form_Element_Text('username');
        $username->setLabel("Username")
            ->setRequired(true)
            ->removeDecorator('errors');  
        
        $password = new Zend_Form_Element_Password('password');
        $password->setLabel("Password")
            ->removeDecorator('errors');    
        
        $submit = new Zend_Form_Element_Submit('Submit');
        $submit->setLabel("Login")
            ->addDecorator(new HTech_Form_Decorator_Button(array('type'=>'submit')));
        
        $this->addElements(array($db,$username,$password,$submit,$locale,$cl));
    }
    
    private function getDbOpt()
    {
        $clientsObj = new Zend_Config_Ini(APPLICATION_PATH . '/configs/config.ini', 'clients');
        $clients = $clientsObj->toArray();
        if (is_array($clients['client'][Zend_Registry::get('cl')])) {
            return $clients['client'][Zend_Registry::get('cl')];
        }
        return false;
    }
    
    private function translate($value)
    {     
        return $this->getTranslator()->translate($value);
    }
}